package com.zzq.springboot1.Dao;

import com.zzq.springboot1.pojo.Department;
import com.zzq.springboot1.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@Repository
public class Employeedao {
    private static Map<Integer,Employee> employees=null;
    @Autowired
    private Departmentdao departmentdao;
    static {
        employees= new HashMap<Integer,Employee>();

        employees.put(1001,new Employee(1001,"AA","A2217633417@qq.com",0,new Department(102,"研发部")));
        employees.put(1002,new Employee(1002,"BB","B2217633417@qq.com",1,new Department(102,"市场部")));
        employees.put(1003,new Employee(1003,"CC","C2217633417@qq.com",0,new Department(103,"教研部")));
        employees.put(1004,new Employee(1004,"DD","D2217633417@qq.com",1,new Department(104,"运营部")));
        employees.put(1005,new Employee(1005,"EE","E2217633417@qq.com",0,new Department(105,"后勤部")));

    }
    //增加员工信息
    //组件自增
    private static Integer initid=1006;
    //员工添加
    public void save(Employee employee){
        if (employee.getId()==null){
            employee.setId(initid++);
        }
        employee.setDepartment(departmentdao.getDepartmentById(employee.getDepartment().getId()));

        employees.put(employee.getId(),employee);
    }
    //查询所有部门信息
    public Collection<Employee> getall(){
        return employees.values();
    }
    //通过id查询员工
    public Employee getEmployeeById(Integer id){
        return employees.get(id);

    }
    //删除所有员工信息
    public void delete(Integer id){
        employees.remove(id);
    }
}
